<template>
    <div>
        <div class="product">
            <h2>采购订单修改</h2>
            <el-form ref="form" :rules="rulesOut" :inline="true" :model="form" label-width="230px"
                style="margin:auto;width:80%;">
                <el-form-item label="供应商" prop="partnerId" class="ww">
                    <el-select v-model="form.partnerId" filterable placeholder="请选择供应商"
                        :filter-method="customerfilterMethod" @change="subCache" style="width: 300px;">
                        <el-option v-for="item in customerdata" :key="item.id" :label="item.name"
                            :value-key="parseInt(item.id)" :value="parseInt(item.id)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="订单日期" prop="dateOrder" class="ww">
                    <el-date-picker clearable v-model="form.dateOrder" type="date" value-format="yyyy-MM-dd"
                        :default-value="new Date()" placeholder="请选择订单日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="交货日期" prop="datePlanned" class="ww">
                    <el-date-picker clearable v-model="form.datePlanned" type="date" value-format="yyyy-MM-dd"
                        :default-value="new Date()" placeholder="请选择交货日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="订单编号" class="ww">
                    <el-input v-model="form.orderNum" placeholder="请输入订单编号"></el-input>
                </el-form-item>
                <el-form-item label="源单据" class="ww">
                    <el-input type="textarea" autosize v-model="form.origin" :disabled="true"></el-input>
                </el-form-item>
                <!-- <el-form-item label="付款条件">
                    <el-input v-model="form.datePlanned" placeholder="审批人"></el-input>
                </el-form-item> -->
                <!-- <el-form-item label="供应商参照">
                    <el-input v-model="form.isProvideInvoice" placeholder="请输入供应商参照"></el-input>
                </el-form-item>
                <el-form-item label="采购单号">           
                    <el-input v-model="form.isTax" placeholder="请输入采购单号"></el-input>
                </el-form-item>     
                 -->
                <!-- <el-form-item label="交货条件">
                    <el-input v-model="form.deliveryConditionsId" placeholder="请输入交货条件"></el-input>
                </el-form-item> -->
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="form.notes" placeholder="请输入备注"></el-input>
                </el-form-item>
            </el-form>
            <div class="tab">
                <div class="btn">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="addorder"
                        :disabled="flag">新增订单行</el-button>
                </div>
                <el-form :model="tableForm" ref="tableForm">
                    <el-table :data="tableForm.tableData" :row-class-name="rowSysGoodsIndex"
                        style="width: 90%; margin: 5px auto 30px;" border :header-cell-style="{ 'text-align': 'center' }"
                        :cell-style="{ 'text-align': 'center' }">
                        <el-table-column prop="sequence" label="序号" width="80">
                        </el-table-column>
                        <el-table-column prop="productTemplateId" label="产品名称" width="300" :render-header="thRequest">
                            <template slot-scope="scope">
                                <el-form-item :prop="'tableData.' + scope.$index + '.productTemplateId'"
                                    :rules="rules.productTemplateId">
                                    <el-select clear v-model="scope.row.productTemplateId" filterable placeholder="请选择产品"
                                        :filter-method="stockfilterMethod" @change="(val) => stockidFun(val, scope.$index)"
                                        class="thRed" style="width: 250px;">
                                        <el-option v-for="item in stockdata" :key="item.id" :label="item.name"
                                            :value="parseInt(item.id)">
                                        </el-option>
                                        <el-option style="color: blue;" label="搜索更多..." value="more"></el-option>
                                        <el-option style="color: blue;" label="创建产品" value="creat"></el-option>
                                    </el-select>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column prop="partMessage" label="说明" width="300">
                            <template slot-scope="scope">
                                <el-input type="textarea" autosize class="borderNone" v-model="scope.row.partMessage" />
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="productUom" label="单位">
                    </el-table-column> -->
                        <!-- <el-table-column prop="surfaceTreatment" label="表面处理">
                    </el-table-column> -->
                        <!-- <el-table-column prop="partMessage" label="预定交货日期">
                        <el-date-picker clearable v-model="form.datePlanned" type="date" value-format="yyyy-MM-dd" :default-value="new Date()"
                        placeholder="请选择订单日期">
                    </el-date-picker>
                    </el-table-column> -->
                        <el-table-column prop="productQty" label="数量" width="150" :render-header="thRequest">
                            <template slot-scope="scope">
                                <el-form-item :prop="'tableData.' + scope.$index + '.productQty'" :rules="rules.productQty">
                                    <el-input class="thRed" v-model="scope.row.productQty" />
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column prop="priceUnit" label="单价" width="150" :render-header="thRequest">
                            <template slot-scope="scope">
                                <el-form-item :prop="'tableData.' + scope.$index + '.priceUnit'" :rules="rules.priceUnit">
                                    <el-input class="thRed" v-model="scope.row.priceUnit"></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column prop="stockNum" label="库存量" width="150">
                            <template slot-scope="scope">
                                <el-input class="borderNone" v-model="scope.row.stockNum" :disabled="true" />
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="worldchampCurrency" label="币种" width="100">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.worldchampCurrency" filterable class="borderNone">
                                    <el-option v-for="item in options" :key="item.id" :label="item.label" :value="item.id">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column> -->
                        <!-- <el-table-column prop="productMaxQty" label="税">
                    </el-table-column> -->
                        <el-table-column prop="priceSubtotal" label="总价" width="150">
                            <template slot-scope="scope">
                                <el-input class="borderNone" v-model="scope.row.priceSubtotal" :disabled="true" />
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                            <template slot-scope="scope">
                                <el-button size="mini" type="text" icon="el-icon-success"
                                    @click="ordersub(scope.row)">确认</el-button>
                                <el-button size="mini" type="text" icon="el-icon-delete"
                                    @click="orderDel(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form>
                <!-- <div class="mes">
                    <p>备注</p>
                    <el-input v-model="form.notes"></el-input>
                </div> -->
                <div class="total">
                    <div class="totalright">
                        <p>总计：<strong>￥{{ amountTotal }}</strong></p>
                        <p>金额大写：<strong>{{ amountTotalDaxie }}</strong></p>
                    </div>
                </div>
            </div>
            <div class="sub">
                <el-button type="primary" @click="submit" style="width:150px">提交</el-button>
            </div>
        </div>
        <!-- 产品搜索弹框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <hr>
            名称：<el-input style="width:150px;margin: 10px 10px" :clearable="true" placeholder="请输入内容" v-model="input2"
                @change="searchcp"></el-input>
            <!-- 型号：<el-input style="width:150px;margin: 30px 10px" :clearable="true" placeholder="请输入内容" v-model="input3"
                @change="searchcp"></el-input> -->
            <el-button type="primary" icon="el-icon-search" @click="searchcp">搜索</el-button>
            <el-table :data="stockListArr" @row-click="selecp">
                <el-table-column label="名称" align="center" prop="name" />
                <el-table-column label="规格" align="center" prop="specification" />
                <!-- <el-table-column label="内部类别" align="center" prop="categId">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.product_category" :value="scope.row.categId" />
                </template>
            </el-table-column> -->
            </el-table>
            <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="stockList" /> -->
        </el-dialog>
        <el-dialog :title="title" :visible.sync="Stockopen" width="800px" append-to-body>
            <el-form ref="Stockform" :model="Stockform" :rules="Stockrules" label-width="150px">
                <el-form-item label="产品名称" prop="name">
                    <el-input v-model="Stockform.name" placeholder="请输入产品名称" />
                </el-form-item>
                <el-form-item label="规格" prop="specification">
                    <el-input v-model="Stockform.specification" placeholder="请输入规格" />
                </el-form-item>
                <el-form-item label="单位" prop="uomId">
                    <el-select clearable v-model="Stockform.uomId" filterable placeholder="请选择单位">
                        <el-option v-for=" dict in dict.type.stock_uom" :key="dict.value" :label="dict.label"
                            :value="parseInt(dict.value)" />
                    </el-select>
                    <!-- <el-input v-model="form.uomId" placeholder="请输入单位" /> -->
                </el-form-item>
                <!-- <el-form-item label="序列" prop="sequence">
          <el-input v-model="form.sequence" placeholder="请输入序列" />
        </el-form-item> -->
                <el-form-item label="产品描述" prop="description">
                    <el-input v-model="Stockform.description" placeholder="请输入库存描述" />
                </el-form-item>
                <!-- <el-form-item label="采购说明" prop="descriptionPurchase">
          <el-input v-model="form.descriptionPurchase" placeholder="请输入采购描述" />
        </el-form-item> -->
                <!-- <el-form-item label="销售描述" prop="descriptionSale">
          <el-input v-model="form.descriptionSale" placeholder="请输入销售描述" />
        </el-form-item> -->
                <!-- <el-form-item label="库存类型" prop="type">
          <el-input v-model="form.type" placeholder="请输入库存类型" />
          
        </el-form-item> -->
                <el-form-item label="内部类别" prop="categId">
                    <el-select clearable filterable v-model="Stockform.categId" placeholder="请选择内部类别">
                        <el-option v-for="dict in dict.type.product_category" :key="dict.value" :label="dict.label"
                            :value="parseInt(dict.value)"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="售价" prop="listPrice">
          <el-input v-model="form.listPrice" placeholder="请输入售价" />
        </el-form-item> -->
                <el-form-item label="体积(m³)" prop="volume">
                    <el-input v-model="Stockform.volume" placeholder="请输入体积" />
                </el-form-item>
                <el-form-item label="重量(kg)" prop="weight">
                    <el-input v-model="Stockform.weight" placeholder="请输入重量" />
                </el-form-item>
                <el-form-item label="可用于销售" prop="saleOk">
                    <!-- <el-input v-model="form.saleOk" placeholder="请输入可用于销售" /> -->
                    <el-radio v-model="Stockform.saleOk" label="t">是</el-radio>
                    <el-radio v-model="Stockform.saleOk" label="f">否</el-radio>
                </el-form-item>
                <el-form-item label="可用于采购" prop="purchaseOk">
                    <!-- <el-input v-model="form.purchaseOk" placeholder="请输入可用于采购" /> -->
                    <el-radio v-model="Stockform.purchaseOk" label="t">是</el-radio>
                    <el-radio v-model="Stockform.purchaseOk" label="f">否</el-radio>
                </el-form-item>
                <el-form-item label="可用于费用" prop="canBeExpensed">
                    <!-- <el-input v-model="form.canBeExpensed" placeholder="请输入可用于费用" /> -->
                    <el-radio v-model="Stockform.canBeExpensed" label="t">是</el-radio>
                    <el-radio v-model="Stockform.canBeExpensed" label="f">否</el-radio>
                </el-form-item>

                <!-- <el-form-item label="Active" prop="active">
          <el-input v-model="form.active" placeholder="请输入Active" />
        </el-form-item> -->
                <el-form-item label="颜色" prop="color">
                    <el-input v-model="Stockform.color" placeholder="请输入颜色" />
                </el-form-item>
                <!-- <el-form-item label="创建者id" prop="createUid">
          <el-input v-model="form.createUid" placeholder="请输入创建者id" />
        </el-form-item> -->
                <!-- <el-form-item label="创建日期" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item> -->
                <!-- <el-form-item label="最后更新者id" prop="writeUid">
          <el-input v-model="form.writeUid" placeholder="请输入最后更新者id" />
        </el-form-item> -->
                <!-- <el-form-item label="最后更新日期" prop="writeDate">
          <el-date-picker clearable v-model="form.writeDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新日期">
          </el-date-picker>
        </el-form-item> -->
                <el-form-item label="最低采购数量" prop="purchaseMinQty">
                    <el-input v-model.number="Stockform.purchaseMinQty" placeholder="请输入最低采购数量" />
                </el-form-item>
                <!-- <el-form-item label="供应商报价" prop="listPrice">
          <el-input v-model="Stockform.listPrice" placeholder="请输入供应商报价" />
        </el-form-item> -->
                <el-form-item label="初始库存" prop="quantyWhenInsert">
                    <el-input v-model.number="Stockform.quantyWhenInsert" placeholder="请输入初始库存" />
                </el-form-item>

                <!-- <el-form-item label="仓库(海内外)" prop="warehouse">
          <el-radio v-model="form.warehouse" label="国内">国内仓</el-radio>
          <el-radio v-model="form.warehouse" label="海外">海外仓</el-radio>
        </el-form-item>
        <el-form-item label="库存不足预警数量" prop="productMinQty">
          <el-input v-model.number="form.productMinQty" placeholder="请输入库存不足预警数量" />
        </el-form-item>
        <el-form-item label="补货推荐数量" prop="productMaxQty">
          <el-input v-model.number="form.productMaxQty" placeholder="请输入补货推荐数量" />
        </el-form-item>
        <el-form-item label="供应商" prop="partnerId">
          <el-select v-model="form.partnerId" filterable placeholder="请选择供应商">
            <el-option v-for="item in supplierdata" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        -->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { listPartner, getPartner } from '@/api/system/partner.js'
import { addStock } from "@/api/system/stock.js"
import { addprocure, stockList1API, delorder1, stockListdedtail, cancelsale, editorderzz1, editorderzzsub, addPerchase, getPerchase, updatePerchase } from '@/api/system/perchase.js';
import { listStock, getStock } from '@/api/system/stock.js'
import purchase from "@/views/system/purchase/index";
export default {
    dicts: ['product_category', 'stock_uom'],
    data() {
        return {
            // 表格行下标
            tableindex: '',
            // 总条数
            total: 0,
            // 弹框产品的搜索
            input2: null,
            // 弹框的数组
            stockListArr: [],
            // 查询产品参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                name: null,
                sequence: null,
                description: null,
                descriptionPurchase: null,
                descriptionSale: null,
                type: null,
                categId: null,
                listPrice: null,
                volume: null,
                weight: null,
                saleOk: null,
                purchaseOk: null,
                uomId: null,
                active: null,
                color: null,
                createUid: null,
                createDate: null,
                writeUid: null,
                writeDate: null,
                specification: null,
                canBeExpensed: null,
                warehouse: null
            },
            //产品搜索弹框
            open: false,
            // 新增订单行按钮禁用
            flag: false,
            // 币种
            options: [{
                id: 3,
                label: 'USD'
            }, {
                id: 22,
                label: 'AUD'
            }, {
                id: 8,
                label: 'CNY'
            }],
            // 修改订单行表单参数
            form2: {},
            // 修改订单行弹框
            orderzzedit: false,
            // 总价
            amountTotal: 0,
            // 大写
            amountTotalDaxie: '零',
            // 用来存储赋值给tabledata
            purchaseOrderParts: [],
            // 外层表单验证
            rulesOut: {
                partnerId: [
                    { required: true, message: "供应商不能为空", trigger: ["blur", 'change'] }
                ],
                datePlanned: [
                    { required: true, message: "订单日期不能为空", trigger: "blur" }
                ],
            },
            // 订单行表单校验
            rules: {
                priceUnit: [
                    { required: true, message: "单价不能为空", trigger: ["blur"] },
                    { pattern: /^(([0-9][0-9]*)|(([0]\.\d{1,2}|[0-9][0-9]*\.\d+$)))$/, message: "只能输入正整数或小数", trigger: "blur" }
                ],
                productTemplateId: [
                    { required: true, message: "产品不能为空", trigger: ["blur", 'change'] }
                ],
                productQty: [
                    { required: true, message: "必须为数字值", trigger: ["blur"] },
                    { pattern: /^[+]{0,1}(\d+)$/, message: '必须为数字值', trigger: ["blur"] }

                ],
            },

            title: '',
            // 订单行弹框
            orderzz: false,
            // 产品数组
            stockdata: [],
            // 外层表单参数
            form: {},
            // 新增订单行表单参数
            form1: {
                priceUnit: null,
                surfaceTreatment: null,
                isPrint: null,
                // worldchampCurrency: null,
                invoiceStatus: null,
                partMessage: null,
                productQty: null,
                // productId:null

            },
            tableForm: {
                tableData: []
            },
            /// 查询供应商参数,用于下拉框
            queryParamsSupplier: {
                pageNum: 1,
                pageSize: 10,
                name: null,
                date: null,
                vat: null,
                website: null,
                comment: null,
                creditLimit: null,
                active: null,
                customer: null,
                supplier: 't',
                employee: null,
                type: null,
                street: null,
                zip: null,
                city: null,
                stateId: null,
                countryId: null,
                email: null,
                phone: null,
                mobile: null,
                isCompany: null,
                partnerShare: null,
                commercialPartnerId: null,
                commercialCompanyName: null,
                writeUid: null,
                writeDate: null,
                customerCode: null,
                deliveryAddress: null
            },
            // 供应商下拉框
            customerdata: [],
            // 产品新增参数
            Stockform: {},
            // 产品表单校验
            Stockrules: {
                // id: [
                //   { required: true, message: "id不能为空", trigger: "blur" }
                // ],
                quantyWhenInsert: [{
                    required: true, message: "初始库存不能为空", trigger: "blur"
                },
                { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }]
                ,
                uomId: [
                    // { required: true, message: '请选择活动区域', trigger: 'change' }
                    { required: true, message: "单位不能为空", trigger: ['change', 'blur'] }
                    // , { validator: checkmm }
                ],
                saleOk: [
                    { required: true, message: "可用于销售不能为空", trigger: "change" }
                ],
                purchaseOk: [
                    { required: true, message: "可用于采购不能为空", trigger: "blur" }
                ],
                canBeExpensed: [
                    { required: true, message: "可用于费用不能为空", trigger: "blur" }
                ],
                name: [
                    { required: true, message: "名称不能为空", trigger: "blur" }
                ],
                type: [
                    { required: true, message: "类型不能为空", trigger: "change" }
                ],
                categId: [
                    { required: true, message: "内部类别不能为空", trigger: "change" }
                ],
                price: [{ required: true, message: '供应商报价不能为空' },
                { pattern: /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g, message: '供应商报价只能输入数字', trigger: 'blur' }

                ],
                purchaseMinQty: [
                    { required: true, message: "最低采购数量不能为空", trigger: "blur" },
                    { type: 'number', message: "最低采购数量只能输入数字", trigger: "blur" }
                ],
                partnerId: [
                    { required: true, message: "供应商不能为空", trigger: "blur" }
                ],
                productMinQty: [{ required: true, message: '库存预警数量不能为空' },
                { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }

                ],
                productMaxQty: [
                    { required: true, message: "补充推荐数量不能为空", trigger: "blur" },
                    { pattern: /^[+]{0,1}(\d+)$/, message: "补充推荐数量只能输入正整数", trigger: "blur" }
                ],
            },
            //   产品新增弹框
            Stockopen: false,
        };
    },
    mounted() {
        let query = this.$route.query.listId;
        this.getSaleOrderWrite(query)
        this.stockList()
        this.customerList()
    },
    methods: {
        // 点击编辑采购订单跳转后请求
        getSaleOrderWrite(query) {
            getPerchase(query).then(res => {
                // console.log(res);
                this.form = res.data
                // 把返回的客户id查询详情并添加到客户选择框中回显
                getPartner(this.form.partnerId).then(resp => {
                    // console.log(resp);
                    const flag1 = this.customerdata.some((item, index) => {
                        if (item.id === this.form.partnerId) {
                            return true
                        }
                    })
                    // console.log(flag1);
                    if (!flag1) {
                        this.customerdata.push(resp.data)
                    }
                    // this.customerdata.push(resp.data)
                    // console.log(this.options);
                })

                // this.stockList()
                this.tableForm.tableData = res.data.purchaseOrderParts
                // console.log(this.tableForm.tableData);
                const aa = (this.tableForm.tableData.map(item => {
                    // 把返回的产品id查询详情并添加到产品选择框中回显
                    getStock(item.productTemplateId).then(res => {
                        // console.log(res);
                        const obj = res.data
                        const flag2 = this.stockdata.some((item2, index) => {
                            if (item2.id === item.productTemplateId) {
                                return true
                            }
                        })
                        // console.log(flag2);
                        if (!flag2) {
                            this.stockdata.push(obj)
                        }

                    })
                }))
                this.amountTotalDaxie = res.data.amountTotalDaxie
                this.amountTotal = res.data.amountTotal
            })
        },
        // 选中供应商时提交一次到缓存，后端需要获取id，来提供产品列表
        subCache() {
            // console.log(this.form);
            addprocure(this.form).then(res => {
                // console.log(res);
                // this.form.parseInt=res.data.parseInt
            })
            this.stockList()
        },
        // 点击新增订单行触发
        addorder() {
            this.flag = true
            let obj = {};
            obj.name = "";
            obj.productQty = "";
            obj.priceUnit = "";
            obj.worldchampCurrency = "";
            obj.partMessage = "";
            // console.log(this.tableForm.tableData);
            if (this.tableForm.tableData === null) {
                this.tableForm.tableData = []
            }
            this.tableForm.tableData.push(obj);
            this.stockList()
        },
        // 订单行确认
        ordersub(row) {
            // console.log(this.tableForm);
            this.$refs["tableForm"].validate((valid) => {
                // console.log(valid);
                if (valid) {
                    this.flag = false
                    const id = row.sequence - 1
                    // console.log(id);
                    // console.log(this.tableForm.tableData);
                    // const arr = []
                    // arr.push(this.tableForm.tableData[id])
                    this.form.purchaseOrderParts = this.tableForm.tableData
                    // console.log(this.form);
                    addprocure(this.form).then(res => {
                        // console.log(res);
                        this.form = res.data
                        this.tableForm.tableData = res.data.purchaseOrderParts
                        this.amountTotalDaxie = res.data.amountTotalDaxie
                        this.amountTotal = res.data.amountTotal

                    })
                }
            })
        },
        // 点击删除订单行触发
        orderDel(row) {
            const that = this
            // console.log(row);
            const id = row.sequence
            // this.delorder(id)
            this.$modal.confirm('是否确认删除产品名称为"' + row.name + '"的订单行？').then(function () {
                return that.delorder(id)
            }).then(() => {
                // this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch((err) => {
                // console.log(err);
            });

        },
        // 删除订单行
        delorder(id) {
            if (this.flag === true) {
                this.tableForm.tableData.pop()
                this.flag = false

            } else {
                // console.log(id);
                delorder1(id).then(res => {
                    // console.log(res);
                    // console.log(this.purchaseOrderParts);
                    this.purchaseOrderParts = res.data.purchaseOrderParts
                    this.form = res.data
                    // console.log(this.form);
                    // console.log(this.form.deliveryConditionsId);
                    this.tableForm.tableData = res.data.purchaseOrderParts
                    this.amountTotalDaxie = res.data.amountTotalDaxie
                    this.amountTotal = res.data.amountTotal
                })
            }
        },
        // 在弹框选中产品回写到产品行
        selecp(row) {
            // console.log(row.id);
            // console.log(this.tableindex);
            this.tableForm.tableData[this.tableindex].productTemplateId = row.id
            this.open = false
            this.stockidFun(row.id)
        },
        // 当前日期
        getDate() {
            var now = new Date();
            var year = now.getFullYear(); //得到年份
            var month = now.getMonth(); //得到月份
            var date = now.getDate(); //得到日期
            var hour = " 00:00:00"; //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
            month = month + 1;
            month = month.toString().padStart(2, "0");
            date = date.toString().padStart(2, "0");
            var defaultDate = `${year}-${month}-${date}`;//
            return defaultDate;
        },
        //表头行必填*
        thRequest(h, colunm) {
            // console.log(h);
            // console.log(colunm);
            // console.log(colunm.column.label);
            return [
                h('span', { style: 'color:#f56c6c' }, '*'),
                h('span', ' ' + colunm.column.label)
            ]

        },
        // 修改采购订单提交
        submit() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    const that = this
                    // console.log(this.form);
                    const aa = this.form
                    // quotationsub(this.form).then(res => {
                    //     console.log(res);
                    // })
                    this.$modal.confirm('是否确认提交修改后的采购订单').then(function () {
                        return updatePerchase(aa).then(res => {
                            // console.log(res)
                        })
                    }).then(() => {
                        // this.getList();
                        // this.getStkBomPart(stockid)
                        this.$modal.msgSuccess("修改成功");
                        this.setOpenEditPur()
                        // this.$router.push({
                        //     path: "/purchase",
                        //     component: purchase,
                        //     redirect: "noRedirect",
                        //     hidden: false,
                        //     alwaysShow: true,
                        // });
                    }).catch((err) => {
                        // console.log(err);
                        this.$message("修改失败");
                    });
                } else {
                    // console.log('error submit!!');
                    return false;
                }
            });
        },
        /** 序号 */
        rowSysGoodsIndex({ row, rowIndex }) {
            row.sequence = rowIndex + 1;
        },
        // 发送给父组件采购订单详情
        setOpenEditPur() {
            // console.log('触发了' + this.$route.query.listId);
            this.$emit('transfer', false, this.$route.query.listId)//触发transfer方法，this.user 为向父组件传递的数据
        },
        // 选择产品赋值
        stockidFun(e, index) {
            // console.log(e);
            if (e == 'more') {
                // console.log('123');
                this.open = true
                this.title = '搜索：产品'
                this.tableindex = index
                this.tableForm.tableData[index].productTemplateId = ''
                this.stockList()
            } else if (e == 'creat') {
                this.Stockopen = true
                this.title = '新增：产品'
                this.reset()
                this.tableindex = index
                this.Stockform.partnerId = this.form.partnerId
                this.tableForm.tableData[index].productTemplateId = ''
                // console.log(this.Stockform);
            } else {
                stockListdedtail(e).then(res => {
                    // console.log(res);
                    const arr = this.tableForm.tableData.map(item => {
                        // return item.sequence==this.tableForm.tableData.length
                        if (item.sequence === this.tableForm.tableData.length) {
                            item.priceUnit = res.data[0].priceUnit
                            item.productQty = res.data[0].productQty
                            item.productUom = res.data[0].productUom
                            // item.worldchampCurrency = res.data[0].worldchampCurrency
                            item.partMessage = res.data[0].partMessage
                            item.name = res.data[0].name
                            item.productId = res.data[0].productId
                        }
                    })




                })
            }
        },
        // 产品弹框的搜索
        searchcp() {

            if (this.input2 === '') {
                this.input2 = null
            }
            stockList1API(this.input2).then(response => {
                // console.log(response);
                this.stockListArr = response.data;
                // this.total = response.total;

                // this.loading = false;
            });
        },
        // 下拉框选择产品组件,用于下拉框显示默认十条
        stockList() {
            stockList1API(this.input2).then(res => {
                // console.log(res);
                this.stockdata = res.data
                this.stockListArr = res.data;
                // console.log(this.stockdata);

            })
        },
        // 产品搜索，用于直接在下拉框搜索
        stockfilterMethod(node, val) {
            // console.log(node, val);
            stockList1API(this.input2).then(res => {
                // console.log(res);
                this.stockdata = res.rows
            })
        },

        // 下拉框选择供应商
        customerList() {
            listPartner(this.queryParamsSupplier).then(res => {
                // console.log(res);
                this.customerdata = res.rows
                // console.log(typeof(this.customerdata[0].id)==='number');

            })
        },
        // 供应商搜索
        customerfilterMethod(node, val) {

            // console.log('val', val, 'node', node)
            // console.log(node);
            const que = {
                name: node,
                pageSize: 100,
                supplier: 't',
            }
            // console.log(que);
            listPartner(que).then(res => {
                // console.log(res);
                this.customerdata = res.rows
            })
        },
        /** 产品提交按钮 */
        submitForm() {
            this.$refs["Stockform"].validate(valid => {
                if (valid) {
                    console.log(this.Stockform);
                    addStock(this.Stockform).then(response => {
                        console.log(response);
                        //   this.$modal.msgSuccess("新增成功");
                        this.Stockopen = false;
                        this.tableForm.tableData[this.tableindex].productTemplateId = response.data
                        this.stockidFun(response.data)
                        this.stockList()
                        //   this.getList();
                    });

                }
            });
        },
        // 取消按钮
        cancel() {
            this.Stockopen = false;
            // this.orderzzedit = false;
            // this.Bomadd = false;
            //   this.reset();
        },
        // 产品表单重置
        reset() {
            this.Stockform = {
                id: null,
                name: null,
                sequence: null,
                description: null,
                descriptionPurchase: null,
                descriptionSale: null,
                type: null,
                categId: null,
                listPrice: null,
                volume: null,
                weight: null,
                saleOk: null,
                purchaseOk: null,
                uomId: null,
                active: null,
                color: null,
                createUid: null,
                createDate: null,
                writeUid: null,
                writeDate: null,
                specification: null,
                canBeExpensed: null,
                warehouse: null
            };
            this.resetForm("Stockform");
        },


    },
    components: {},
    props: {
        fid: {
            type: Number, default: null
        }
    },
    watch: {},
    computed: {},
    created() { },
};
</script>
<style lang="scss" scoped>
.ww {
    width: 600px;
    // border: 1px red solid;
}


.product {
    width: 100%;
    background: #fff;
    border: 1px rgb(232, 228, 228) solid;
    // box-shadow: 0 3px 20px -15px #000000;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    margin: 10px auto;
}

h2 {
    text-align: center;
    line-height: 60px;
}

.btn {
    margin-left: 5%;
}

.sub {
    // width: 80%;
    // border: 1px red solid;
    text-align: center;
    margin-bottom: 20px;

}

.mes {
    margin-left: 5%;
    width: 600px;
}

.total {

    // border: 1px red solid;
    width: 90%;
    margin: 50px auto;

    // margin: 40px 60% 30px;
    // border-top: 2px gray solid;
    // text-align:right;
    .totalright {
        width: 30%;
        // float: right;
        margin-left: 70%;
        border-top: 2px gray solid;

        p {
            line-height: 40px;
            text-align: right;
        }
    }

}

.thRed {
    // height: 200px;
    margin-top: 22px;
}
</style>